package dao.mysql;

import dao.*;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;

import sun.util.logging.resources.logging;

public class DAOFactoryImpl extends DAOFactory {
	
	public static String DATASOURCE_CONTEXT="java:comp/env/jdbc/SysAdmin";
	
	private IUserDAO userDAO= new UserDAO();
	
	public Connection getJNDIConnection(){
		Connection result=null;
		try{
			Context initialContext = new InitialContext();
			if (initialContext == null)
				System.out.println("JNDI problem. Cannot get InitialContext.");
			
			DataSource datasource = (DataSource)initialContext.lookup(DATASOURCE_CONTEXT);
			
			if ( datasource != null){
				result = datasource.getConnection();
			}
			else{
				System.out.println("Failed to lookup datasource.");
			}
		}
		
		catch(NamingException ex){
			System.out.println("Naming Exception problem.");
		}
		
		catch(SQLException ex)
		{
			System.out.println("SQL Exception problem.");
		}
		
		return result;
		
	}
	
	public IUserDAO getUserDAO()
	{
		return userDAO;
	}
}
